package com.lanou.dllo.findfood.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.lanou.dllo.findfood.util.Constant;

/**
 * Created by dllo on 15/10/31.
 */
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    public MySQLiteOpenHelper(Context context, String name,
                              SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    /**
     * 第一次创建数据库时会回调的方法
     * 一般在此方法中建立基础表 执行创建表的操作
     */

    //"create table "与表名称之间有空格
    //" Integer,"前面有空格
    //_msgId作为主键  是自动增长
    //更新升级数据库
    @Override
    public void onCreate(SQLiteDatabase db) {
    //创建一个首页广告的数据库
        String sqHomeViewpager= "create table "+ Constant.TABLE_NAME_HOME_VIEWPAGER

                + "(" + Constant.COLUMN_HOME_VIEWPAGER_DEAL_ID + " Integer,"
                +Constant.COLUMN_HOME_VIEWPAGER_DESCRIPTION + " varchar(255),"
                +Constant.COLUMN_HOME_VIEWPAGER_TITLE + " varchar(255),"
                +Constant.COLUMN_HOME_VIEWPAGER_IMAGE + " varchar(255),"
                +"_msgId integer primary key autoincrement"
                +")";

        db.execSQL(sqHomeViewpager);

//首页下面表
        String sqlHomeRecylerView= "create table " + Constant.TABLE_NAME_HOME_RECYLECLER
                + "("
                +Constant.COLUMN_HOME_RECYLECLER_COMMENT + " varchar(255),"
                +Constant.COLUMN_HOME_RECYLECLER_FOOD_NAME + " varchar(255),"
                +Constant.COLUMN_HOME_RECYLECLER_USER_NAME + " varchar(255),"
                +Constant.COLUMN_HOME_RECYLECLER_PLACE_NAME + " varchar(255),"
                +Constant.COLUMN_HOME_RECYLECLER_PICTURE_URL + " varchar(255),"
                +Constant.COLUMN_HOME_RECYLECLER_USER_IMAGE + " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlHomeRecylerView);//去执行这条语句


        String sqlFindViewPage= "create table " + Constant.TABLE_NAME_FIND_TOP_VIEWPAGE
                + "(" + Constant.COLUMN_FIND_TOP_VIEWPAGE_FOOD_ID + " Integer,"
                +Constant.COLUMN_FIND_TOP_VIEWPAGE_IMGURL + " varchar(255),"
                +Constant.COLUMN_FIND_TOP_VIEWPAGE_TITLE + " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlFindViewPage);

        String sqlMenuOne= "create table " + Constant.TABLE_NAME_MENU_BEAUTY
                + "(" + Constant.COLUMN_MENU_BEAUTY_IMG + " varchar(255),"
                +Constant.COLUMN_MENU_BEAUTY_KEYWORDS + " varchar(255),"
                +Constant.COLUMN_MENU_BEAUTY_DESCRIPTION + " varchar(255),"
                +Constant.COLUMN_MENU_BEAUTY_NAME+ " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlMenuOne);
        String sqlMenuTwo= "create table " + Constant.TABLE_NAME_MENU_BODY
                + "(" + Constant.COLUMN_MENU_BODY_IMG + " varchar(255),"
                +Constant.COLUMN_MENU_BODY_KEYWORDS + " varchar(255),"
                +Constant.COLUMN_MENU_BODY_DESCRIPTION + " varchar(255),"
                +Constant.COLUMN_MENU_BODY_NAME+ " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlMenuTwo);

        String sqlMenuThere= "create table " + Constant.TABLE_NAME_MENU_HEALTH
                + "(" + Constant.COLUMN_MENU_HEALTH_IMG + " varchar(255),"
                +Constant.COLUMN_MENU_HEALTH_DESCRIPTION + " varchar(255),"
                +Constant.COLUMN_MENU_HEALTH_KEYWORDS + " varchar(255),"
                +Constant.COLUMN_MENU_HEALTH_NAME+ " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlMenuThere);

        String sqlMenuFour= "create table " + Constant.TABLE_NAME_MENU_LOSEWEIGHT
                + "(" + Constant.COLUMN_MENU_LOSEWEIGHT_IMG + " varchar(255),"
                +Constant.COLUMN_MENU_LOSEWEIGHT_DESCRIPTION + " varchar(255),"
                +Constant.COLUMN_MENU_LOSEWEIGHT_KEYWORDS + " varchar(255),"
                +Constant.COLUMN_MENU_LOSEWEIGHT_NAME+ " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqlMenuFour);

        //用户表
        String sqluser= "create table " + Constant.TABLE_NAME_USER
                + "("
                +Constant.COLUMN_USER_NAME + " varchar(255),"
                +Constant.COLUMN_USER_PASSWORD+ " varchar(255),"
                +"_msgId integer primary key autoincrement"
                + ")";
        db.execSQL(sqluser);



    }



    /**
     * 当表的版本发生改变时会回调的方法
     * 一般在此方法中做一些表升级的操作
     */
    @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        super.onDowngrade(db, oldVersion, newVersion);
    }
}
